
$(document).ready(function(){
	
	$('.data-table').dataTable({
		"aaSorting": [[5, 'desc']],
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
		"sDom": '<""l>t<"F"fp>'
	});
	
	$('input[type=checkbox],input[type=radio],input[type=file]').uniform();
	
	$('select').select2();
	
	$("span.icon input:checkbox, th input:checkbox").click(function() {
		var checkedStatus = this.checked;
		var checkbox = $(this).parents('.widget-box').find('tr td:first-child input:checkbox');		
		checkbox.each(function() {
			this.checked = checkedStatus;
			if (checkedStatus == this.checked) {
				$(this).closest('.checker > span').removeClass('checked');
			}
			if (this.checked) {
				$(this).closest('.checker > span').addClass('checked');
			}
		});
	});	
	
	// Form Validation
    $("#basic_validate").validate({
    	
		rules:{
			appName:{
				required:true
			},
			appInstanceNum:{
				required:true,
				number:true
			},
			userIds:{
				required:true
			}
		},
		ignore: ':hidden:not("#userIds")', 
		errorClass: "help-inline",
		errorElement: "span",
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
	$(".btn-success").click(function() {
		$("#basic_validate").submit();
	});
	
	$(".btn-info").click(function() {
		$("#basic_validate").submit();
	});
	
	$(".btn-danger").click(function() {
		location.href="appMain";
	});
	
});